package com.qing.cheng.controller;


import com.qing.cheng.dto.QcCourseDto;
import com.qing.cheng.dto.ResponseMessage;
import com.qing.cheng.dto.SuccessRes;
import com.qing.cheng.service.QcCourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    Logger log = LoggerFactory.getLogger(CourseController.class);

    private final QcCourseService courseService;

    public CourseController(QcCourseService courseService) {
        this.courseService = courseService;
    }


    /**
     * 发布课程
      */
    @RequestMapping("/publishingCourses")
    public ResponseMessage publishingCourses(@RequestBody QcCourseDto courseDto) {
        try{
            courseService.publishingCourses(courseDto);
            return SuccessRes.success(null);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());

        }
        return null;
    }

    /**
     * 获取课程详情
     * @param courseId
     * @return
     */
    @RequestMapping("/getCourse/{courseId}")
    public ResponseMessage getCourse(@PathVariable("courseId")Integer courseId) {
        try{
            return SuccessRes.success(courseService.getOneById(courseId));
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return null;
    }


}
